﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ConnectToDatabase;

namespace Server
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private TcpChannel tcpChannel;
        private WellKnownObjectMode mode =WellKnownObjectMode.Singleton;

        public MainWindow()
        {
            InitializeComponent();

        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            tcpChannel = new TcpChannel(Int32.Parse(txtPort.Text));
            ChannelServices.RegisterChannel(tcpChannel, false);                                                                  

            //dang ky doi tuong INSETDB
            RemotingConfiguration.RegisterWellKnownServiceType(typeof (InsertDB), "INSERTDB_OBJECT", mode);
                                                               
            //dang ky doi tuong SELECTDB
            RemotingConfiguration.RegisterWellKnownServiceType(typeof (SelectDB), "SELECTDB_OBJECT", mode);

            //dang ky doi tuong UPDATEDB
            RemotingConfiguration.RegisterWellKnownServiceType(typeof (UpdateDB), "UPDATEDB_OBJECT", mode);

            //dang ky doi tuong DELETEDB
            RemotingConfiguration.RegisterWellKnownServiceType(typeof (DeleteDB), "DELETEDB_OBJECT", mode);

            //dang ky doi tuong SHOWDB
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ShowDB), "SHOWDB_OBJECT", mode);

            //dang ky doi tuong SETID
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(SetID), "SETID_OBJECT", mode);

            //dang ky doi tuong OTHER
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(OtherHandle), "OTHERHANDLE_OBJECT", mode);

            //dang ky doi tuong EXCEL
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ExportExcel), "EXPORTEXCEL_OBJECT", mode);

            //dang ky doi tuong SELECTDATA
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(SelectData), "SELECTDATA_OBJECT", mode);

            lblTrangThai.Content = "Server đã khởi động";
        }
    }
}
